﻿using System;
using System.Globalization;
using System.Runtime.Serialization;
using Istace.Framework.Mapping.Core.Interfaces;

namespace Istace.Framework.Mapping.Core.Exceptions
{
    /// <summary>
    /// Thrown when try to get an object from a repository based on a key for which no objects are associated
    /// </summary>
    [Serializable]
    public class ObjectNotExistingException<T> : RepositoryBaseException<T>
    {


        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectNotExistingException{T}"/> class.
        /// </summary>
        public ObjectNotExistingException()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectNotExistingException{T}"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        public ObjectNotExistingException(string message) : base(message)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectNotExistingException{T}"/> class.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="exception">The exception.</param>
        public ObjectNotExistingException(string message, Exception exception) : base(message, exception)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectNotExistingException{T}"/> class.
        /// </summary>
        /// <param name="info">The info.</param>
        /// <param name="context">The context.</param>
        protected ObjectNotExistingException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
        }

        /// <summary>
        /// Default .ctor
        /// </summary>
        /// <param name="index">The index used for object request</param>
        /// <param name="targetRepository">The repository which throw the exception</param>
        public ObjectNotExistingException(string index, IIndexedRepository<T> targetRepository)
            : base(String.Format(CultureInfo.InvariantCulture, "The object of type '{0}' with the key '{1}' doesn't exist in this repository.", typeof(T).FullName, index), 
            null, 
            index, 
            targetRepository)
        {
        }
    }
}
